﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(PhotoManager))]
[RequireComponent(typeof(BackpackManager))]
public class PhoneController : MonoBehaviour {
	///相片界面
	[SerializeField] GameObject photoMenu;
	///摄像机视觉
	[SerializeField] GameObject cameraScreen;
	///显示相片
	[SerializeField] GameObject photoesScreen;
	///显示背包
	[SerializeField] GameObject backpackMenu;

	PhotoManager photoMan;
	BackpackManager backpackMan;

	void Start(){
		photoMan = GetComponent<PhotoManager> ();
		backpackMan = GetComponent<BackpackManager> ();
	}

	void Update () {
		if (Input.GetKeyDown (KeyCode.Keypad1)) {
			ShowBackpackMenu ();
		} else if (Input.GetKeyDown (KeyCode.Keypad2)) {
			ShowPhotoMenu ();
		} else if (Input.GetKeyDown (KeyCode.Keypad3)) {
			ShowCameraScreen ();
		} else if (Input.GetKeyDown (KeyCode.Keypad4)) {
			ShowPhotoesScreen ();
		}
	}

	void ShowPhotoMenu(bool enablePhoto = true){
		photoMenu.SetActive (enablePhoto);
		backpackMenu.SetActive (!enablePhoto);
		photoMan.enabled = enablePhoto;
		backpackMan.enabled = !enablePhoto;
	}

	void ShowBackpackMenu(){
		photoMenu.SetActive (false);
		backpackMenu.SetActive (true);
		photoMan.enabled = false;
		backpackMan.enabled = true;
	}

	void ShowCameraScreen(){
		if (photoMenu.activeSelf) {
			cameraScreen.SetActive (true);
			photoesScreen.SetActive (false);
		}
	}

	void ShowPhotoesScreen(){
		if (photoMenu.activeSelf) {
			cameraScreen.SetActive (false);
			photoesScreen.SetActive (true);
		}
	}
}
